Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor handling of TOML config files for runtimes #643

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

elezar
Copy link
Member

@elezar elezar commented Aug 9, 2024

This change refactors the toml config file handlig for runtimes
such as containerd or crio. A toml.Loader is introduced that
encapsulates loading the required file.

This can be extended to allow other mechanisms for loading
loading the current config.

return LoadBytes(outb.Bytes())
}

type tomlFromCRI struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that crictl info doesn't provide the full config for CRI-O, this is probably not a useful toml source candidate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just stick to the file-based and CLI-based sources for now IMO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I've removed the logic from this PR though. We can add it as a follow-up.

@elezar elezar force-pushed the refactor-toml-source branch 2 times, most recently from 5e45d7f to f3c8ea0 Compare September 27, 2024 10:39
@elezar elezar changed the title WIP: Add TomlSource as abstract concept Refactor handling of TOML config files for runtimes Sep 27, 2024
@elezar elezar self-assigned this Sep 27, 2024
@elezar elezar marked this pull request as ready for review September 27, 2024 10:40
Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar elezar force-pushed the refactor-toml-source branch from f3c8ea0 to aa8ec43 Compare September 27, 2024 13:39
@@ -14,19 +14,19 @@
# limitations under the License.
**/

package engine
package config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this been moved from engine to config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this represents a Raw config. Importing enging.Raw does not make the intent as clear as config.Raw when imported.

logger logger.Interface
path string
logger logger.Interface
reference toml.Loader
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the name reference may be a bit too vague. How about configRef?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about tomlSource?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to configSource instead. One thing I would like to do as a (non-critical) follow-up is to also refactor the docker config handling to make use of a source like this. Not a blocker for the CRI-O work though.

}

if os.IsNotExist(err) {
return Empty.Load()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fail fast here and error out indicating that the file wasn't found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not how the current code works. We load an empty config if the file doesn't exist.

Can you think of a reason to fail instead? How would a user indicate that the config is optional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A path to a file that does not exist should be considered as invalid input IMO. So we should error out accordingly

@@ -222,6 +223,7 @@ func setupConfig(o *options) error {

cfg, err := crio.New(
crio.WithPath(o.Config),
crio.WithReference(toml.FromFile(o.Config)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think WithConfigReference may be more suggestive of the struct field's role and purpose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think WithConfigSource is clearer. Have updated.

@elezar elezar force-pushed the refactor-toml-source branch from aa8ec43 to 033aa5c Compare September 30, 2024 12:21
This change refactors the toml config file handlig for runtimes
such as containerd or crio. A toml.Loader is introduced that
encapsulates loading the required file.

This can be extended to allow other mechanisms for loading
loading the current config.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar elezar force-pushed the refactor-toml-source branch from 033aa5c to bf2bdfd Compare September 30, 2024 12:24
@tariq1890 tariq1890 merged commit 10bafd1 into NVIDIA:main Sep 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants